<?php
// +----------------------------------------------------------------------
// | User: DaMing
// +----------------------------------------------------------------------
// | Email: 3228985941@qq.com
// +----------------------------------------------------------------------
// | Date: 2021/12/15
// +----------------------------------------------------------------------
// | Time: 13:18
// +----------------------------------------------------------------------

namespace app\adminapi\validate;


use app\dm\validates\BaseValidate;

class AdminValidate extends BaseValidate
{
    protected $rule = [
        'AdminID|ID'           => 'require|number',
        'AdminName|账户名'        => 'require|length:5,20|alphaDash|unique:admin', // 字母和数字，下划线_及破折号-
        'AdminPassword|密码'     => 'require|length:8,16|regex:^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$',
        'ConfirmPassword|再次密码' => 'require|confirm:AdminPassword',
        'RoleID|角色'            => 'require|number',
        'RealName|姓名'          => 'chsDash', // 汉字、字母、数字和下划线_及破折号-
        'Tel|手机号'              => 'require|mobile',
        'AdminType|账户类型'       => 'require|in:1,2',
        'Keywords|搜索关键字'       => 'chsDash', // 汉字、字母、数字和下划线_及破折号-
        'Page|当前页'             => 'number',
        'Limit|每页数量'           => 'number',
        'Remark|备注'            => 'max:50',
        'AdminStatus|状态'       => 'in:0,1'
    ];

    protected $message = [
        'AdminID.number'      => 'ID参数错误',
        'AdminType.require'   => '账户类型不能为空555555555555555',
        'AdminType.in'        => '账户类型错误',
        'AdminName.unique'    => '账户名已存在',
        'AdminPassword.regex' => '密码条件不符合',
        'RoleID.require'      => '请选择角色',
        'RoleID.number'       => '角色参数错误',
        'Page.number'         => '页数参数错误',
        'Limit.number'        => '数量参数错误',
        'AdminStatus'         => '状态参数错误',
    ];

    // 场景
    protected $scene = [
        'list'   => ['AdminType', 'Keywords', 'Page', 'Limit'],
        'info'   => ['AdminID'],
        'create' => ['AdminName', 'AdminType', 'RoleID', 'AdminPassword', 'ConfirmPassword', 'RealName', 'Tel', 'Remark'],
        'del'    => ['AdminID'],
        'async'  => ['AdminID', 'AdminStatus']
    ];

    /**
     * update场景
     * @return AdminValidate
     */
    public function sceneUpdate()
    {
        return $this->only(['AdminID', 'RoleID', 'AdminPassword', 'ConfirmPassword', 'RealName', 'Tel', 'Remark'])
            ->remove('AdminPassword', ['require'])
            ->remove('ConfirmPassword', ['require'])
            ->remove('Tel', ['require']);
    }
}